Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/google-protobuf

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/google-protobuf

TypeScript definitions for google-protobuf

  • 3.15.12
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
increased by6.16%
Maintainers
1
Weekly downloads
 
Created

What is @types/google-protobuf?

@types/google-protobuf provides TypeScript type definitions for the google-protobuf library, which is used for working with Protocol Buffers in JavaScript. Protocol Buffers are a method developed by Google for serializing structured data, similar to XML or JSON.

What are @types/google-protobuf's main functionalities?

Creating a Protocol Buffer Message

This code demonstrates how to create a custom Protocol Buffer message class by extending the Message class from google-protobuf. It includes methods to get and set a field in the message.

const { Message } = require('google-protobuf');

class MyMessage extends Message {
  constructor() {
    super();
    this.myField = '';
  }

  getMyField() {
    return this.myField;
  }

  setMyField(value) {
    this.myField = value;
  }
}

const message = new MyMessage();
message.setMyField('Hello, World!');
console.log(message.getMyField());

Serializing and Deserializing Messages

This code demonstrates how to serialize a Protocol Buffer message to binary format and then deserialize it back to a message object. This is useful for efficient data storage and transmission.

const { MyMessage } = require('./my_message_pb');

const message = new MyMessage();
message.setMyField('Hello, World!');

// Serialize to binary format
const bytes = message.serializeBinary();

// Deserialize from binary format
const deserializedMessage = MyMessage.deserializeBinary(bytes);
console.log(deserializedMessage.getMyField());

Using Enums in Protocol Buffers

This code demonstrates how to define and use enums in Protocol Buffer messages. Enums are useful for representing a fixed set of constants in a message.

const { Message, Field, Enum } = require('google-protobuf');

const MyEnum = {
  UNKNOWN: 0,
  FIRST: 1,
  SECOND: 2
};

class MyMessage extends Message {
  constructor() {
    super();
    this.myEnumField = MyEnum.UNKNOWN;
  }

  getMyEnumField() {
    return this.myEnumField;
  }

  setMyEnumField(value) {
    this.myEnumField = value;
  }
}

const message = new MyMessage();
message.setMyEnumField(MyEnum.FIRST);
console.log(message.getMyEnumField());

Other packages similar to @types/google-protobuf

FAQs

Package last updated on 21 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc